package com.tx.java8.date;

import org.junit.jupiter.api.Test;

import java.time.DayOfWeek;
import java.time.LocalDateTime;
import java.time.temporal.TemporalAdjusters;

/**
 *  TemporalAdjuster使用
 */
public class DateTest3 {

    @Test
    public void test1(){
        LocalDateTime ld = LocalDateTime.now();

        LocalDateTime ld4 = ld.with(TemporalAdjusters.firstDayOfMonth());
        System.out.println(ld4);

        //自定义规则,得到下一个工作日
        LocalDateTime ld3 = ld.with((ldt)->{
           LocalDateTime l2 = (LocalDateTime)ldt;
            DayOfWeek dayOfWeek = l2.getDayOfWeek();
            switch (dayOfWeek){
                case FRIDAY:{
                    l2 = l2.plusDays(3);
                }break;
                case SATURDAY:{
                    l2 = l2.plusDays(2);
                }break;
                default:{
                    l2 = l2.plusDays(1);
                }
            }
            return l2;
        });
        System.out.println(ld3);
    }
}
